package 队列;

import java.util.PriorityQueue;

/**
 * @PackageName: 队列
 * @ClassName: LeetCode2558
 * @Author: chen jinxu
 * @Date: 2023/10/31 21:56
 * @Description: //TODO
 */
public class LeetCode2558 {
    public static void main(String[] args) {
        System.out.println(pickGifts(new int[]{25, 64, 9, 4, 100}, 4));
        System.out.println(pickGifts(new int[]{1, 1, 1, 1}, 4));
    }

    public static long pickGifts(int[] gifts, int k) {
        PriorityQueue<Integer> qu = new PriorityQueue<>((a, b) -> b - a);
        for (int gift : gifts) {
            qu.offer(gift);
        }
        while (k > 0) {
            k--;
            Integer x = qu.poll();
            qu.offer((int) Math.sqrt(x));
        }
        long result = 0;
        while (!qu.isEmpty()) {
            result += qu.poll();
        }
        return result;
    }
}
